home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Prog / M / May MacUser Program.cpt / miniGenApp Src / MenuUtil.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-03-29  |  4.1 KB  |  164 lines  |  [TEXT/KAHL]

  1. /* *****************************************************************************
  2.     FILE:             MenuUtil.c
  3.     
  4.     DESCRIPTION:     Menu Utilities
  5.  
  6.     AUTHOR:            Kurt W.G. Matthies
  7.         
  8.     Copyright © 1990 by Code of the West, Inc., All Rights Reserved.
  9.  
  10.     
  11.     Revision History:
  12.     ==========================================================
  13.     3.30.90    -    May 1990 MacUser Release
  14.     ==========================================================
  15.  
  16.    ***************************************************************************** */
  17. #include "AppGlobals.h"
  18. #include "MenuConstants.h"
  19.  
  20. #include "AboutBoxPr.h"
  21. #include "DocUtilPr.h"
  22. #include "ShellPr.h"
  23. #include "WindowUtilPr.h"
  24.  
  25. #include "MenuUtilPr.h"
  26.  
  27. /* ---------------------  Local Prototypes  -------------------------------- */
  28. void            doAppleMenu            ( short );
  29. void            doFileMenu            ( short );
  30. void            doEditMenu            ( short );
  31.  
  32. /* -----------------------------------------------------------------------------
  33.     doMenu -        determine what item in which menu was selected.
  34.     3.30.9090kwgm    route control to the action function
  35. -------------------------------------------------------------------------------*/
  36. void 
  37. doMenu (menuResult)
  38.     long          menuResult;
  39. {
  40.     short         menuID, itemNumber;
  41.  
  42.     menuID = HiWord (menuResult);        /* which menu */
  43.     itemNumber = LoWord (menuResult);    /* what item */
  44.     
  45.     switch (menuID) 
  46.     {
  47.         case kAppleMenuID:
  48.             doAppleMenu (itemNumber);
  49.             break;
  50.             
  51.         case kFileMenuID:
  52.             doFileMenu (itemNumber);
  53.             break;
  54.             
  55.         case kEditMenuID:
  56.             doEditMenu (itemNumber);
  57.             break;
  58.             
  59.     }
  60.         
  61.     HiliteMenu (0);
  62.  
  63. }    /* doMenu */
  64.  
  65. /* -----------------------------------------------------------------------------------
  66.     doFileMenu -    file menu item routing function
  67.     3.30.90kwgm
  68. -------------------------------------------------------------------------------------- */
  69. static void 
  70. doFileMenu (theItem)
  71.     short    theItem;
  72. {
  73.     switch (theItem) 
  74.     {
  75.         case kNewItem:
  76.             doNewDoc ();
  77.             break;
  78.             
  79.         case kCloseItem:
  80.             doCloseDoc (FrontWindow ());
  81.             break;
  82.             
  83.         case kQuitItem:
  84.             cleanExit (true);
  85.             break;
  86.     }
  87.     
  88. } /* doFileMenu */
  89.  
  90. /* -----------------------------------------------------------------------------------
  91.     doAppleMenu -    apple menu item routing function
  92.     3.30.90kwgm
  93. -------------------------------------------------------------------------------------- */
  94. static void 
  95. doAppleMenu (theItem)
  96.     short        theItem;
  97. {
  98.     Str255        itemName;
  99.     
  100.     if (theItem == 1)
  101.          doAboutBox ();
  102.     else
  103.     {    /* desk accesories get called here */
  104.         GetItem (GetMHandle (kAppleMenuID), theItem, itemName);
  105.         OpenDeskAcc (itemName);
  106.     }
  107.     
  108. } /* doAppleMenu */
  109.  
  110. /* -----------------------------------------------------------------------------------
  111.     doEditMenu -     edit menu item routing function.
  112.     3.30.90kwgm        Supplied for desk accessory compatibility
  113. -------------------------------------------------------------------------------------- */
  114. static void 
  115. doEditMenu (theItem)
  116.     short    theItem;
  117. {
  118.     SystemEdit (theItem);
  119. }    /* doEditMenu */
  120.  
  121. /* ----------------------------------------------------------------------------------
  122.     fixMenus -        fixup the applications menus 
  123.     3.30.90kwgm
  124. ------------------------------------------------------------------------------------- */
  125. void
  126. fixMenus ()
  127. {
  128.     DocPtr        theDoc;
  129.     
  130.     theDoc = FrontWindow();
  131.     
  132.     if (theDoc)
  133.     {
  134.         DisableItem (gFileMenu, kNewItem);
  135.         EnableItem (gFileMenu, kCloseItem);
  136.         
  137.         if (((WindowPeek) theDoc)->windowKind  >= 1)    /* Generic vindow */
  138.         {
  139.             DisableItem (gEditMenu, kUndoItem);
  140.             DisableItem (gEditMenu, kCutItem);
  141.             DisableItem (gEditMenu, kCopyItem);
  142.             DisableItem (gEditMenu, kPasteItem);
  143.             DisableItem (gEditMenu, kClearItem);
  144.         }
  145.         else
  146.         {
  147.             EnableItem (gEditMenu, kUndoItem);
  148.             EnableItem (gEditMenu, kCutItem);
  149.             EnableItem (gEditMenu, kCopyItem);
  150.             EnableItem (gEditMenu, kPasteItem);
  151.             EnableItem (gEditMenu, kClearItem);
  152.             EnableItem (gFileMenu, 0);
  153.         }
  154.     }
  155.     else
  156.     {
  157.         EnableItem (gFileMenu, kNewItem);
  158.         DisableItem (gFileMenu, kCloseItem);
  159.     }
  160. } /* fixMenus */
  161.  
  162. /* ===============================  EOF  =======================================
  163.     Copyright © 1990 by Code of the West, Inc. All Rights Reserved.
  164. ================================================================================ */